<template>
  <div class="app-container">
    <el-form class="formList" :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch"
      label-width="88px">
      <el-row>

        <el-form-item label="主营品类" prop="mainCategory">
          <el-select v-model="queryParams.mainCategory" placeholder="请选择主营品类" clearable size="small" filterable>
            <el-option v-for="dict in codeOptions" :key="dict.dictValue" :label="dict.dictLabel"
              :value="dict.dictValue" />
          </el-select>
        </el-form-item>

        <el-form-item label="店铺名称" prop="platformName">
          <el-input v-model="queryParams.platformName" placeholder="请输入店铺名称" clearable size="small"
            @keyup.enter.native="handleQuery" />
        </el-form-item>

        <el-form-item label="使用状态" prop="isAuth">
          <el-select v-model="queryParams.isAuth" placeholder="请选择状态" clearable size="small">
            <el-option v-for="dict in statusOptions" :key="dict.dictValue" :label="dict.dictLabel"
              :value="dict.dictValue" />
          </el-select>
        </el-form-item>

        <el-form-item style="margin-left: 22px;">
          <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
          <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
        </el-form-item>

      </el-row>

    </el-form>

    <el-row :gutter="10" class="row-mbinfo">

      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <div class="divTable">
      <el-table v-loading="loading" :data="infoList">
        <el-table-column label="店铺logo图" align="center" prop="platformLogUrl" :show-overflow-tooltip="true">
          <template slot-scope="scope">
            <el-image v-if="scope.row.platformLogUrl != null && scope.row.platformLogUrl != '' " slot="reference"
              :src="scope.row.platformLogUrl" class="image-rows" :preview-src-list="[scope.row.platformLogUrl]">
            </el-image>
          </template>
        </el-table-column>
        <el-table-column label="店铺名称" align="left" prop="platformName" :show-overflow-tooltip="true" />
        <el-table-column label="主营品类" align="center" prop="mainCategory" :show-overflow-tooltip="true" />

        <el-table-column label="店铺地址" align="center" prop="updateTime" width="180" sortable>
          <template slot-scope="scope">
            <span>{{scope.row.platformProvince }}{{scope.row.platformCity }}{{scope.row.platformArea }}{{scope.row.platformAddress }}</span>
          </template>
        </el-table-column>
        <el-table-column label="商家电话" align="left" prop="servePhone" :show-overflow-tooltip="true" />
        <el-table-column label="使用状态" align="center" prop="isAuth" :show-overflow-tooltip="true"
          :formatter="StatusFormat" />

        <el-table-column label="创建时间" align="center" prop="createTime" width="200" sortable>
          <template slot-scope="scope">
            <span>{{ parseTime(scope.row.createTime, '{y}-{m}-{d} {h}:{i}:{s}') }}</span>
          </template>
        </el-table-column>
        <el-table-column label="到期时间" align="center" prop="authTime" width="200" sortable>
          <template slot-scope="scope">
            <span>{{ parseTime(scope.row.authTime, '{y}-{m}-{d} {h}:{i}:{s}') }}</span>
          </template>
        </el-table-column>
        <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
          <template slot-scope="scope">
            <el-button size="mini" type="text" icon="el-icon-edit" @click="handleUpdate(scope.row)"
              v-hasPermi="['platform:info:edit']">修改到期时间</el-button>
            <el-button v-if="0>1" size="mini" type="text" icon="el-icon-edit" @click="handleUpdate(scope.row,0)"
              v-hasPermi="['platform:info:edit']">改为测试</el-button>
            <el-button v-if="0>1" size="mini" type="text" icon="el-icon-edit" @click="handleUpdate(scope.row,1)"
              v-hasPermi="['platform:info:edit']">改为正式</el-button>
          </template>
        </el-table-column>
      </el-table>

      <pagination v-show="total>0" :total="total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize"
        @pagination="getList" />
    </div>

    <el-dialog title="修改状态" :visible.sync="open" width="400px" append-to-body :destroy-on-close="true" @close="halog">

      <div class="block" style="margin-bottom: 20px;">
        <span class="demonstration" style="margin-left: 16%; margin-right: 5%;">状态</span>
        <el-radio-group v-model="authStatus">
          <el-radio label="1">正式</el-radio>
          <el-radio label="0">使用</el-radio>
        </el-radio-group>
      </div>
      <div class="block">
        <span class="demonstration" style="margin-right:5%">选择到期时间</span>
        <el-date-picker value-format="yyyy-MM-dd HH:mm:ss" v-model="time" type="datetime" placeholder="选择日期时间"
          :picker-options="pickerOptions">
        </el-date-picker>
      </div>

      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">修 改</el-button>
        <el-button @click="handCloseDetail">取 消</el-button>
      </div>


    </el-dialog>



  </div>
</template>

<script>
  import {
    listStoreInfo,
    getInfo,
    delInfo,
    addInfo,
    updateInfo,
    updateTime
  } from "@/api/platform/info";
  import ImageUpload from '@/components/ImageUpload';

  export default {
    name: "Info",
    components: {
      ImageUpload,
    },
    data() {
      return {
        uid: "",
        authStatus: null,
        time: "",
        open: false,
        // 遮罩层
        loading: true,
        // 选中数组
        ids: [],
        // 非单个禁用
        single: true,
        // 非多个禁用
        multiple: true,
        // 显示搜索条件
        showSearch: true,
        // 总条数
        total: 0,
        // 店铺信息表格数据
        infoList: [],
        // 弹出层标题
        title: "",
        //查看详细标题
        viewTitle: "",
        // 是否显示弹出层
        open: false,
        //是否显示查看详细弹出层
        viewOpen: false,
        //查看详细数据
        showData: [],
        // 查询参数
        queryParams: {
          pageNum: 1,
          pageSize: 10,
          platformNo: null,
          companyname: null,
          mainCategory: null,
          platformName: null,
          platformLogUrl: null,
          servePhone: null,
          platformType: null,
          platformRemark: null,
          contactPerson: null,
          platformEmail: null,
          platformPhone: null,
          platformProvince: null,
          platformCity: null,
          platformArea: null,
          platformAddress: null,
          dataStatus: null,
          isAuth: null,
          licenseImgUrl: null,
          authTime: null,
          authUpdateUid: null,
          updateUser: null,
          updateTime: null,
          createTime: null,
          createUser: null,
          platformText: null,
          platformImage: null,
          orderService: null,
          caseUid: null,
          supportImg: null,
          dataSort: null
        },
        columns: [{
            label: '排序',
            dataIndex: 'platformUid',
          },
          {
            label: '店铺编号',
            dataIndex: 'platformNo',
          },
          {
            label: '企业名称',
            dataIndex: 'companyname',
          },
          {
            label: '主营品类',
            dataIndex: 'mainCategory',
          },
          {
            label: '店铺名称',
            dataIndex: 'platformName',
          },
          {
            label: '店铺logo图',
            dataIndex: 'platformLogUrl',
          },
          {
            label: '商家服务电话',
            dataIndex: 'servePhone',
          },
          {
            label: '0无版本/1基础版/2专业版/3旗舰版',
            dataIndex: 'platformType',
          },
          {
            label: '店铺详情',
            dataIndex: 'platformRemark',
          },
          {
            label: '入驻联系人',
            dataIndex: 'contactPerson',
          },
          {
            label: '入驻邮箱',
            dataIndex: 'platformEmail',
          },
          {
            label: '入驻手机号',
            dataIndex: 'platformPhone',
          },
          {
            label: '店铺省份',
            dataIndex: 'platformProvince',
          },
          {
            label: '店铺城市',
            dataIndex: 'platformCity',
          },
          {
            label: '店铺区域',
            dataIndex: 'platformArea',
          },
          {
            label: '店铺详细地址，不含省市区',
            dataIndex: 'platformAddress',
          },
          {
            label: '状态 0无效1有效',
            dataIndex: 'dataStatus',
          },
          {
            label: '认证状态（0待认证1已认证）',
            dataIndex: 'isAuth',
          },
          {
            label: '营业执照URL',
            dataIndex: 'licenseImgUrl',
          },
          {
            label: '认证时间',
            dataIndex: 'authTime',
          },
          {
            label: '认证操作人',
            dataIndex: 'authUpdateUid',
          },
          {
            label: '修改人',
            dataIndex: 'updateUser',
          },
          {
            label: '修改时间',
            dataIndex: 'updateTime',
          },
          {
            label: '创建时间',
            dataIndex: 'createTime',
          },
          {
            label: '创建人',
            dataIndex: 'createUser',
          },
          {
            label: '分享的文案',
            dataIndex: 'platformText',
          },
          {
            label: '分享的图片 建议 500*400',
            dataIndex: 'platformImage',
          },
          {
            label: '售后说明',
            dataIndex: 'orderService',
          },
          {
            label: '案例风格ID',
            dataIndex: 'caseUid',
          },
          {
            label: '技术支持图片',
            dataIndex: 'supportImg',
          },
          {
            label: '排序',
            dataIndex: 'dataSort',
          },
        ],
        // 表单参数
        form: {},
        // 表单校验
        rules: {},
        statusOptions: [],
        codeOptions: [],
        pickerOptions: {
          shortcuts: [{
            text: '一周',
            onClick(picker) {
              const date = new Date();
              date.setTime(date.getTime() + 3600 * 1000 * 24 * 7);
              picker.$emit('pick', date);
            }
          }, {
            text: '一个月',
            onClick(picker) {
              const date = new Date();
              date.setTime(date.getTime() + 3600 * 1000 * 24 * 30);
              picker.$emit('pick', date);
            }
          }, {
            text: '三个月',
            onClick(picker) {
              const date = new Date();
              date.setTime(date.getTime() + 3600 * 1000 * 24 * 30 * 3);
              picker.$emit('pick', date);
            }
          }, {
            text: '六个月',
            onClick(picker) {
              const date = new Date();
              date.setTime(date.getTime() + 3600 * 1000 * 24 * 30 * 6);
              picker.$emit('pick', date);
            }
          }, {
            text: '一年',
            onClick(picker) {
              const date = new Date();
              date.setTime(date.getTime() + 3600 * 1000 * 24 * 30 * 12);
              picker.$emit('pick', date);
            }
          }]
        },

      };
    },
    created() {
      this.getList();
      this.getDicts("platform_trade_code").then(response => {
        this.codeOptions = response.data;
      });
      this.getDicts("platform_auth_status").then(response => {
        this.statusOptions = response.data;
      });
    },
    methods: {
      StatusFormat(row, column) {
        return this.selectDictLabel(this.statusOptions, row.isAuth);
      },
      /** 查询店铺信息列表 */
      getList() {
        this.loading = true;
        listStoreInfo(this.queryParams).then(response => {
          this.infoList = response.rows;
          this.total = response.total;
          this.loading = false;
        });
      },
      // 取消按钮
      cancel() {
        this.open = false;
        this.reset();
      },
      // 表单重置
      reset() {
        this.form = {
          platformUid: null,
          platformNo: null,
          companyname: null,
          mainCategory: null,
          platformName: null,
          platformLogUrl: null,
          servePhone: null,
          platformType: null,
          platformRemark: null,
          contactPerson: null,
          platformEmail: null,
          platformPhone: null,
          platformProvince: null,
          platformCity: null,
          platformArea: null,
          platformAddress: null,
          dataStatus: "0",
          isAuth: null,
          licenseImgUrl: null,
          authTime: null,
          authUpdateUid: null,
          updateUser: null,
          updateTime: null,
          createTime: null,
          createUser: null,
          platformText: null,
          platformImage: null,
          orderService: null,
          caseUid: null,
          supportImg: null,
          dataSort: null
        };
        this.resetForm("form");
      },
      /** 搜索按钮操作 */
      handleQuery() {
        this.queryParams.pageNum = 1;
        this.getList();
      },
      /** 重置按钮操作 */
      resetQuery() {
        this.resetForm("queryForm");
        this.handleQuery();
      },
      // 多选框选中数据
      handleSelectionChange(selection) {
        this.ids = selection.map(item => item.platformUid)
        this.single = selection.length !== 1
        this.multiple = !selection.length
      },
      /** 新增按钮操作 */
      handleAdd() {
        this.reset();
        this.open = true;
        this.title = "添加店铺信息";
      },
      /** 查看详情按钮操作 **/
      handleShowDetail(row) {
        this.viewOpen = true;
        this.viewTitle = "查看店铺信息";
        this.showData = [];
        this.columns.forEach(item => {
          this.showData.push({
            label: item.label,
            value: row[item.dataIndex]
          })
        })
      },
      handCloseDetail() {
        this.open = false
      },
      /** 修改按钮操作 */
      handleUpdate(row) {
        this.open = true;
        this.time = row.authTime;
        this.uid = row.platformUid;
        this.authStatus = row.isAuth;
      },
      halog() {
        this.time = "";
        this.uid = "";
        this.authStatus = null;
      },
      /** 提交按钮 */
      submitForm() {
        if (this.time == "" || this.time == null) {
          this.$message.error("请选择到期时间");
        }
        if (this.authStatus == "" || this.authStatus == null) {
          this.$message.error("请选择状态");
        }
        let data = {
          platformUid: this.uid,
          authTime: this.time,
          isAuth: this.authStatus
        }
        updateTime(data).then(response => {
          this.$message.success("修改成功！")
          this.open = false;
          this.getList();
        })
      },
      /** 删除按钮操作 */
      handleDelete(row) {
        const platformUids = row.platformUid || this.ids;
        this.$confirm('是否确认删除店铺信息编号为"' + platformUids + '"的数据项?', "警告", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(function() {
          return delInfo(platformUids);
        }).then(() => {
          this.getList();
          this.msgSuccess("删除成功");
        })
      },
      /** 导出按钮操作 */
      handleExport() {
        this.download('platform/info/export', {
          ...this.queryParams
        }, `platform_info.xlsx`)
      }
    }
  };
</script>
